/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cliente;

    import java.awt.Color;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
/**
 *
 * @author pedro
 */
public class FileSaver implements SceneSaver{
    @Override
    public Object load(String name) {
        FileInputStream file;
        try {
            //cargamos el fichero
            file = new FileInputStream(name);
            try {
                // creamos un objeto para leer del fichero
                ObjectInputStream in = new ObjectInputStream(file);
                Object obj;   
                obj = in.readObject();
                in.close();
                file.close();
                return obj;
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(FileSaver.class.getName()).log(Level.SEVERE, null, ex);
                return false;   
            } catch (IOException ex) {
                Logger.getLogger(FileSaver.class.getName()).log(Level.SEVERE, null, ex);
                return false;   
            }
            } catch (FileNotFoundException ex) {
            Logger.getLogger(FileSaver.class.getName()).log(Level.SEVERE, null, ex);
            return false;  
        }
    }

    @Override
    public Boolean write(String name, Object obj) {
        FileOutputStream file;
        try {
            // cargamos el fichero
            file = new FileOutputStream(name);
            ObjectOutputStream out;
            // creamos un objeto para escribir el fichero
            out = new ObjectOutputStream(file);
            out.writeObject(obj);
            out.close();
            file.close();
            return true;
        } catch (IOException ex) {
            Logger.getLogger(FileSaver.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
        
    }
   
}
